package com.OjSystem.common.core.aspect;

import com.OjSystem.common.core.errorCode.CommonErrorCode;
import com.OjSystem.common.core.result.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionAspect {
    @ExceptionHandler(value = Exception.class)
    public CommonResult<?> ExceptionHandler(Exception exception) {
        log.error("发生未知错误：", exception.getMessage());
        System.out.println(exception);
        return CommonResult.fail(CommonErrorCode.INTERNAL_SERVER_ERROR.getCode(), exception.getMessage());
    }
}
